import java.util.Scanner;









class TreeNode {
    TreeNode left;
    TreeNode right;

    char val;

    public TreeNode( char val) {
        this.val = val;
    }
}
// 注意类名必须为 Main, 不要有任何 package xxx 信息
 class Main {

    String s="abc##de#g##f###";
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        String s = in.nextLine();

        TreeNode root = creatTree(s);


        order(root);


    }

    private static void order(TreeNode root) {
        if (root == null) return;

        order(root.left);
        System.out.print(root.val+" ");
        order(root.right);

    }

    public static int i = 0;

    private static TreeNode creatTree(String s) {

        TreeNode root = null;

        if (s.charAt(i) != '#') {
            root = new TreeNode(s.charAt(i));
            i++;
            root.left = creatTree(s);
            root.right = creatTree(s);


        } else {
            i++;
        }

        return root;




    }
}